//
// Created by LONG on 2020/10/19.
//

#ifndef O5G_SRC_O5GUE_L3_INCLUDE_L3DEF_H_
#define O5G_SRC_O5GUE_L3_INCLUDE_L3DEF_H_

#include "../../../../lib/csp/include/cspApi.h"
#include "../../include/ueApi.h"
#include "../../lcore/include/commDef.h"


typedef enum
{
    UE_L3_UE_SM_STATE_INIT,
    UE_L3_UE_SM_STATE_WAIT_L1_CONFIG_RSP,
    UE_L3_UE_SM_STATE_WAIT_L1_SYNC_RSP,
    UE_L3_UE_SM_STATE_WAIT_L2_CONFIG_RSP,
    UE_L3_UE_SM_STATE_WAIT_L2_START_RSP,
    UE_L3_UE_SM_STATE_CELL_SEARCH_SUCC,
    UE_L3_UE_SM_STATE_BUTT
} E_UeL3UeSmState;

typedef enum
{
    UE_L3_UE_SM_EVENT_CELL_SEARCH_TRIGGER,
    UE_L3_UE_SM_EVENT_RECV_L1_CONFIG_RSP,
    UE_L3_UE_SM_EVENT_RECV_L1_SYNC_RSP,
    UE_L3_UE_SM_EVENT_RECV_L2_CONFIG_RSP,
    UE_L3_UE_SM_EVENT_RECV_L2_START_RSP,
    UE_L3_UE_SM_EVENT_BUTT
} E_UeL3UeSmEvent;

typedef struct UeL3UeInst
{
    uint32_t inUse;
    uint32_t ueId;

    uint32_t ueIdx;

    E_UeL3UeSmState state;
    S_FsmInst *ueSmInst;
} S_UeL3UeInst;

typedef struct UeL3Context
{
    pthread_t tid;
    uint64_t tick10ms;
    S_OsSelect selector;
    int l2SockFd;
    S_Poller *poller;

    S_Fsm *ueFsm;
    S_FixRingBuffer *ueFsmEvtQue;

    uint32_t ueInstNum;
    S_UeL3UeInst ueInst[UE_UE_INST_NUM_MAX];
    char sockRecvBuffer[SOCK_BUFFER_SIZE];
} S_UeL3Context;

extern S_UeL3Context *gpUeL3Context;

#endif //O5G_SRC_O5GUE_L3_INCLUDE_L3DEF_H_
